<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-song-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">歌曲名：</label>
				<div class="col-sm-8">
					<input id="songName" name="songName" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">级别：</label>
				<div class="col-sm-8">
					<select id="level" class="form-control m-b" th:with="type=${@dict.getType('zl_subject_level')}">
						<option th:each="dict : ${type}" th:data-dictSort="${dict.dictSort}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">星级：</label>
				<div class="col-sm-8">
					<select id="starLevel" class="form-control m-b" th:with="type=${@dict.getType('zl_song_xingji')}">
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictSort}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">参考课时费：</label>
				<div class="col-sm-8">
					<input id="teacherCost" name="teacherCost" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control" type="text">
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">

        var options_level_class = eval("[[${@dict.getTypeJson('zl_subject_level')}]]".replace(/&quot;/g, "'"));
        var options;
        var _options_html = "";
        options=options_level_class;
        for (var i = 0; i < options.length; i++) {
            var option = options[i];
            console.log(option)
            _options_html = _options_html + "<option value='" + option.dictValue + "' data-dictSort='"+option.dictSort+"'>" +  option.dictLabel + "</option>"
        }
        $("#level").html(_options_html);
        $("#teacherCost").val($("#level option:selected").attr("data-dictSort"))

        $("#teacherCost").val($("#level option:selected").attr("data-dictSort"))
        $("#level").on("change", function () {
            $("#teacherCost").val($("#level option:selected").attr("data-dictSort"))
        })

		var prefix = ctx + "project/song"
		$("#form-song-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});
		


        function submitHandler() {
            if ($.validate.form()) {
                add();
            }
        }

        function add() {

            var songId = $("input[name='songId']").val();
            var songName = $("input[name='songName']").val();
            var level = $("#level option:selected").val();
            var starLevel = $("#starLevel option:selected").val();
            var teacherCost = $("input[name='teacherCost']").val();
            var remark =$("input[name='remark']").val();


            $.ajax({
                cache : true,
                type : "POST",
                url : ctx + "project/song/add",
                data : {
                    "songId": songId,
                    "songName": songName,
                    "level": level,
                    "starLevel": starLevel,
                    "teacherCost": teacherCost,
                    "remark": remark

                },
                async : false,
                error : function(request) {
                    $.modal.alertError("系统错误");
                },
                success : function(data) {
                    $.operate.saveSuccess(data);
                }
            });
        }

	</script>
</body>
</html>
